package com.sh1604.duitang.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sh1604.duitang.R;
import com.sh1604.duitang.mybean.HomeCollectDataBean;
import com.squareup.picasso.Picasso;

/**
 * Created by cay on 2016/7/22.
 */
public class TitleView extends LinearLayout {
    private Context context;
    private TextView tv_title;
    private TextView tv_imgandcollect;
    private TextView tv_name;
    private CircleImageView civ;

    public TitleView(Context context) {
        this(context,null);
    }

    public TitleView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public TitleView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
       this.context = context;
        LayoutInflater.from(context).inflate(R.layout.home_collect_title,this);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_imgandcollect = (TextView) findViewById(R.id.tv_imgandcollect);
        tv_name = (TextView) findViewById(R.id.tv_name);
        civ = (CircleImageView) findViewById(R.id.civ_collect);
    }

    public void setData(HomeCollectDataBean.DataBean data){
        if (data != null){
            String name = data.getName().toString();
            int count = data.getCount();
            int like_count = data.getLike_count();
            String username = data.getUser().getUsername();
            String avatar = data.getUser().getAvatar();

            tv_title.setText(name);
            tv_imgandcollect.setText(count+"张图片."+like_count+"人收藏");
            Picasso.with(context).load(avatar).into(civ);
            tv_name.setText(username);
        }
    }
}
